{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-06-12 09:41:08,659 - modelscope - INFO - PyTorch version 2.1.2 Found.\n",
      "2024-06-12 09:41:08,663 - modelscope - INFO - TensorFlow version 2.12.0 Found.\n",
      "2024-06-12 09:41:08,664 - modelscope - INFO - Loading ast index from /home/liyaze/.cache/modelscope/ast_indexer\n",
      "2024-06-12 09:41:08,812 - modelscope - INFO - Loading done! Current index file version is 1.14.0, with md5 45f0cd7d198297b65e8d236e06ce416c and a total number of 976 components indexed\n",
      "/home/liyaze/anaconda3/envs/longchain/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "from modelscope.pipelines import pipeline\n",
    "from modelscope.utils.constant import Tasks\n",
    "import numpy as np\n",
    "import cv2\n",
    "import math\n",
    "from PIL import Image, ImageDraw, ImageFont"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2024-06-12 09:41:10,508 - modelscope - INFO - Use user-specified model revision: v1.0.0\n",
      "2024-06-12 09:41:10.882225: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.\n",
      "2024-06-12 09:41:10.931021: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.\n",
      "To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.\n",
      "2024-06-12 09:41:12,595 - modelscope - INFO - initiate model from /home/liyaze/.cache/modelscope/hub/damo/cv_proxylessnas_ocr-detection-db-line-level_damo\n",
      "2024-06-12 09:41:12,597 - modelscope - INFO - initiate model from location /home/liyaze/.cache/modelscope/hub/damo/cv_proxylessnas_ocr-detection-db-line-level_damo.\n",
      "2024-06-12 09:41:12,598 - modelscope - INFO - initialize model from /home/liyaze/.cache/modelscope/hub/damo/cv_proxylessnas_ocr-detection-db-line-level_damo\n",
      "2024-06-12 09:41:13,597 - modelscope - INFO - loading model from dir /home/liyaze/.cache/modelscope/hub/damo/cv_proxylessnas_ocr-detection-db-line-level_damo\n",
      "2024-06-12 09:41:14,730 - modelscope - INFO - loading model done\n"
     ]
    }
   ],
   "source": [
    "ocr_detection = pipeline(Tasks.ocr_detection, model='damo/cv_proxylessnas_ocr-detection-db-line-level_damo', model_revision='v1.0.0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = '/home/FAST_DATA_MIRROR/Langchain-Chatchat-master/pdf_tools/output/none/none.png'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "res = ocr_detection(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'polygons': array([], dtype=float64)}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(res['polygons'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0,)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
      "\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
      "\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n",
      "\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
     ]
    }
   ],
   "source": [
    "res['polygons'].shape"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "longchain",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
